﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using BalanceManager.Helpers;
using BalanceManager.Model;
using BalanceManager.ViewModels;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using BalanceManager.Resources;
using GestureEventArgs = System.Windows.Input.GestureEventArgs;

namespace BalanceManager
{
    public partial class MainPage : BindablePage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}

        private void LongListSelector_ItemRealized(object sender, ItemRealizationEventArgs e)
        {
            var fundFlow = e.Container.Content as FundFlow;
            var contextMenu = new ContextMenu();

            var deleteMenuItem = new MenuItem { Header = "Удалить" };
            deleteMenuItem.Command = (DataContext as MainViewModel).DeleteFundFLowCommand;
            deleteMenuItem.CommandParameter = fundFlow;

            var editMenuItem = new MenuItem { Header = "Изменить" };
            editMenuItem.Command = (DataContext as MainViewModel).EditFundFlowCommand;
            editMenuItem.CommandParameter = fundFlow;

            contextMenu.Items.Add(editMenuItem);
            contextMenu.Items.Add(deleteMenuItem);
            ContextMenuService.SetContextMenu(e.Container, contextMenu);
        }

        private void LongListSelector_ItemUnrealized(object sender, ItemRealizationEventArgs e)
        {
            
        }
    }
} 